package com.css.controller;

import com.css.Main;
import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.layout.Pane;

/**
 * <p>
 * -
 * </p>
 *
 * @author css
 * @since 2021/4/6 0006
 */
public class MainController extends BaseController{
    @FXML
    private Pane setting;
    @FXML
    private Pane monitor;
    @FXML
    private Pane person;

    public void showSetting(javafx.scene.input.MouseEvent event) {
        //更新JavaFX的主线程的代码放在此处
        setting.setVisible(true);
        monitor.setVisible(false);
        person.setVisible(false);
    }

    public void showMonitor(javafx.scene.input.MouseEvent event) {
        //更新JavaFX的主线程的代码放在此处
        setting.setVisible(false);
        monitor.setVisible(true);
        person.setVisible(false);
    }

    public void showPerson(javafx.scene.input.MouseEvent event) {
        Platform.runLater(() -> {
            //更新JavaFX的主线程的代码放在此处
            setting.setVisible(false);
            monitor.setVisible(false);
            person.setVisible(true);
        });
    }

    private double xOffset = 0;
    private double yOffset = 0;

    public void titleDragged(javafx.scene.input.MouseEvent event) {
        event.consume();
        Platform.runLater(() -> {
            if (event.getEventType() == javafx.scene.input.MouseEvent.MOUSE_PRESSED) {
                xOffset = event.getSceneX();
                yOffset = event.getSceneY();
            } else if (event.getEventType() == javafx.scene.input.MouseEvent.MOUSE_DRAGGED) {
                Main.getStage().setX(event.getScreenX() - xOffset);
                if (event.getScreenY() - yOffset < 0) {
                    Main.getStage().setY(0);
                } else {
                    Main.getStage().setY(event.getScreenY() - yOffset);
                }
            }
        });
    }
}
